<?php

namespace app\api\controller\wanlshop;

use addons\wanlshop\library\WanlPay\WanlPay;
use app\admin\model\wanlshop\AddressSpot;
use app\common\controller\Api;
use app\common\model\TestContent;
use think\Exception;
use think\exception\ValidateException;
use think\Log;
use think\Request;
use EasyWeChat\Factory;
use WeChatPay\Crypto\Rsa;
use WeChatPay\Builder;
use WeChatPay\Util\PemUtil;
use WeChatPay\Util\MediaUtil;
use fast\Http;
//服务商相关接口
class Separate extends Api
{
    /**
     * 无需登录的方法,同时也就不需要鉴权了
     * @var array
     */
    protected $noNeedLogin = ['*'];
    /**
     * 无需鉴权的方法,但需要登录
     * @var array
     */
    protected $noNeedRight = ['*'];

    //获取基础配置
    public function __construct(Request $request = null,$arr = [])
    {
        parent::__construct($request);
        //获取 wanlshop 配置文件
        $data = (new WanlPay())->getPublicConfig('wechat');
        $data = array_merge($data,$arr);

        //增加子商户对应参数 及 Easywechat 相关参数
        $data['sub_appid'] = $data['app_id'];
        $data['cert_path'] = $data['cert_client'];
        $data['key_path'] = $data['cert_key'];
        $this->config = $data;

        $this->payment = Factory::payment($data);

        // 「商户API证书」的「证书序列号」
        $this->merchantCertificateSerial = '701D3C885B67EB839DFF7D257B49EAAFAE9932FE';
        // 从本地文件中加载「微信支付平台证书」，用来验证微信支付应答的签名（平台证书  非  商户证书）
        $this->platformCertificateFilePath = "file://"."/www/wwwroot/c.hrbyuecai.com/addons/wanlshop/certs/wechatpay.pem";

        // 商户号
        $merchantId = $this->config['mch_id'];
        // 从本地文件中加载「商户API私钥」，「商户API私钥」会用来生成请求的签名
        $merchantPrivateKeyFilePath = "file://".$this->config['key_path'];
        $merchantPrivateKeyInstance = Rsa::from($merchantPrivateKeyFilePath, Rsa::KEY_TYPE_PRIVATE);
        $this->merchantPrivateKeyInstance = $merchantPrivateKeyInstance;
        // 「商户API证书」的「证书序列号」
        $merchantCertificateSerial = $this->merchantCertificateSerial;
        // 从本地文件中加载「微信支付平台证书」，用来验证微信支付应答的签名
        $platformCertificateFilePath = $this->platformCertificateFilePath;
        $platformPublicKeyInstance = Rsa::from($platformCertificateFilePath, Rsa::KEY_TYPE_PUBLIC);

        // 从「微信支付平台证书」中获取「证书序列号」
        $platformCertificateSerial = PemUtil::parseCertificateSerialNo($platformCertificateFilePath);

        $this->platformCertificateSerial = $platformCertificateSerial;
        // 做一个匿名方法，供后续方便使用，$platformPublicKeyInstance 见初始化章节

        $this->instance = Builder::factory([
            'mchid'      => $merchantId,
            'serial'     => $merchantCertificateSerial,
            'privateKey' => $merchantPrivateKeyInstance,
            'certs'      => [
                $platformCertificateSerial => $platformPublicKeyInstance,
            ],
        ]);


    }

    /**
     * //发起单次分账
     * @param $transaction_id   //微信内订单号
     * @param $out_trade_no     //商户订单号
     * @param $account          //分账账号
     * @param $name             //商户名称
     * @param $money            //分账金额
     */

    public function share($transaction_id,$out_trade_no,$money = 1,$account = "1680098009",$name="悦采科技",$data = [],$moneyPick=null,$type = 0)
    {

        //添加收款方
        $receiver = [
            "type"          => $type == 0?"MERCHANT_ID":"PERSONAL_OPENID",   //如果是个人自提点传openid
            "account"       => $account,
            "name"          => $name,//商户全称
            "relation_type" => $account == '1680098009' ? "SERVICE_PROVIDER" : "PARTNER"
        ];
        $res = $this->payment->profit_sharing->addReceiver($receiver);
        if(count($data) >0){
            $res = $this->payment->profit_sharing->addReceiver($data);
        }
        //进行单次分账
        $receivers = [
            [
                "type"        => $type == 0?"MERCHANT_ID":"PERSONAL_OPENID",
                "account"     => $account,
                "amount"      => $money,
                "description" => "分到商户"
            ]
        ];
        if($moneyPick){
            $receivers = [
                  [
                      "type"        => "MERCHANT_ID",
                      "account"     => $account,
                      "amount"      => $money,
                      "description" => "分到商户"
                  ],
                [
                        "type"        =>$type == 0?"MERCHANT_ID":"PERSONAL_OPENID",
                        "account"     => $data['account'],
                        "amount"      => $moneyPick,
                        "description" => "分到自提点"
                ],
            ];
        }
        $sharing = $this->payment->profit_sharing->share($transaction_id,$out_trade_no,$receivers);
        Log::write($sharing);
//        halt($sharing);
        $arr = [
            'bool'  =>  false,
            'msg'   =>  '分账失败',
        ];
        if(isset($sharing['result_code'])){

            if($sharing['result_code'] == 'FAIL'){
                $arr = [
                    'bool'  =>  false,
                    'msg'   =>  $sharing['err_code_des'],
                ];
            }else if($sharing['return_code']== 'SUCCESS' && $sharing['result_code']== 'SUCCESS'){
                $arr = [
                    'bool'  =>  true,
                    'msg'   =>  '分账成功',
                ];
            }
        }

        return $arr;
    }


    public function multiShare($transaction_id,$out_trade_no,$receiver ,$multiShare)
    {
        foreach ($receiver as $v){
            $res = $this->payment->profit_sharing->addReceiver($v);
        }
        //添加收款方
        $sharing = $this->payment->profit_sharing->multiShare($transaction_id,$out_trade_no,$multiShare);
        $arr = [
            'bool'  =>  false,
            'msg'   =>  '分账失败',
        ];
        if(isset($sharing['result_code'])){

            if($sharing['result_code'] == 'FAIL'){
                $arr = [
                    'bool'  =>  false,
                    'msg'   =>  $sharing['err_code_des'],
                ];
            }else if($sharing['return_code']== 'SUCCESS' && $sharing['result_code']== 'SUCCESS'){
                $arr = [
                    'bool'  =>  true,
                    'msg'   =>  '分账成功',
                ];

                //分账成功后进行完结
                $params = [
                    "transaction_id" => $transaction_id,
                    "out_order_no"   => $out_trade_no,
                    "description"    => "分账完结"
                ];
                $this->payment->profit_sharing->markOrderAsFinished($params);

            }
        }

        return $arr;
    }

    public function application($shop_id,$type = true)
    {
        if($type){
            $shop = \app\api\model\wanlshop\Shop::where('id',$shop_id)->find();
        }else{
            $shop = AddressSpot::where('id',$shop_id)->find();
        }
        $business_code = $this->config['mch_id'].time();
        $license_copy = $this->wx_upload_image($shop->license_copy);
        $contact_id_doc_copy = $this->wx_upload_image($shop->contact_id_doc_copy);
        $arr = [
            'business_code'             => $business_code,//业务申请编号
            "contact_info"              => [//超级管理员信息
                'contact_type'              => "LEGAL",//超级管理员类型
                'contact_name'              => $this->encryptor($shop->contact_name),//超级管理员姓名
                'contact_id_doc_type'       => 'IDENTIFICATION_TYPE_IDCARD',//超级管理员证件类型
                'contact_id_number'         => $this->encryptor($shop->contact_id_number),//超级管理员身份证件号码
                'contact_id_doc_copy'       => $contact_id_doc_copy,//超级管理员证件正面照片
                'contact_id_doc_copy_back'  => $this->wx_upload_image($shop->contact_id_doc_copy_back),//超级管理员证件反面照片
                'contact_period_begin'      => $shop->contact_period_begin,//超级管理员证件有效期开始时间
                'contact_period_end'        => $shop->contact_period_end,//超级管理员证件有效期结束时间
                'openid'                    => '',//超级管理员微信OpenID
                'mobile_phone'              => $this->encryptor($shop->mobile_phone),//联系手机
                'contact_email'             => $this->encryptor($shop->contact_email),//联系邮箱
            ],
            'subject_info'              =>  [//主体资料
                'subject_type'              => $shop->subject_type,//主体类型
                'business_license_info'     => [//-营业执照  主体为个体户/企业
                    'license_copy'              => $license_copy,//营业执照照片
                    'license_number'            => $shop->license_number,//注册号/统一社会信用代码
                    'merchant_name'             => $shop->merchant_name,//注册号/商户名称
                    'legal_person'              => $shop->contact_name,//个体户经营者/法人姓名
                    'license_address'           => $shop->license_address,//个体户经营者/注册地址
                    'period_begin'              => $shop->license_period_begin,//有效期限开始日期
                    'period_end'                => $shop->license_period_end,//有效期限结束日期
                ],
//                'certificate_info'      =>  [//主体为政府机关/事业单位/其他组织
//                    'cert_copy'                 => $shop->cert_copy? $this->wx_upload_image($shop->cert_copy):'',//登记证书照片
//                    'cert_type'                 => $shop->cert_type??"",//登记证书类型
//                    'cert_number'               => $shop->cert_number??"",//证书号
//                    'merchant_name'             => $shop->merchant_name??"",//商户名称
//                    'company_address'           => $shop->company_address??"",//注册地址
//                    'legal_person'              => $shop->contact_name??"",//法定代表人
//                    'period_begin'              => $shop->certificate_period_begin??"",//有效期限开始日期
//                    'period_end'                => $shop->certificate_period_end??"",//有效期限结束日期
//                ],
                'identity_info'         =>  [//经营者/法人身份证件
                    'id_holder_type'            => "LEGAL",//证件持有人类型
                    'id_doc_type'               =>  $shop->contact_id_doc_type,//证件类型
                    "id_card_info"              => [
                        'id_card_copy'              =>  $this->wx_upload_image($shop->contact_id_doc_copy),//身份证人像面照片
                        'id_card_national'          =>  $this->wx_upload_image($shop->contact_id_doc_copy_back),//身份证国徽面照片
                        'id_card_name'              =>  $this->encryptor($shop->contact_name),//身份证姓名
                        'id_card_number'            =>  $this->encryptor($shop->contact_id_number),//身份证号码
                        'id_card_address'           =>  $this->encryptor($shop->id_card_address),//身份证居住地址
                        'card_period_begin'         =>  $shop->contact_period_begin,//身份证有效期开始时间
                        'card_period_end'           =>  $shop->contact_period_end,//身份证有效期结束时间
                    ]
                ],

            ],
            "business_info"             =>  [//-经营资料
                'merchant_shortname'            => $shop->shopname?$shop->shopname:$shop->merchant_name,//商户简称
                'service_phone'                 => $shop->mobile_phone,//客服电话
                'sales_info'                => [//经营场景
                    'sales_scenes_type'             =>  ["SALES_SCENES_MP"],//经营场景类型
                    'mp_info'               => [//公众号场景
                        'mp_appid'                  =>   $this->config['sub_appid']//服务商公众号AppID
                    ],
                    'mini_program_info'     => [//小程序场景
                        'mini_program_appid'        =>  "",//服务商小程序AppID
                    ],
                ],
            ],

            "settlement_info"           =>  [//-结算规则
                'settlement_id'                 =>  $shop->subject_type == "SUBJECT_TYPE_INDIVIDUAL"?"719":'716',//入驻结算规则ID
                'qualification_type'            => $shop->qualification_type?$shop->qualification_type: "电商平台",//所属行业
            ],

            "bank_account_info"         =>  [//--结算银行账户
                'bank_account_type'             =>   $shop->bank_account_type,//账户类型
                'account_name'                  =>   $shop->bank_account_type == "BANK_ACCOUNT_TYPE_CORPORATE" ? $this->encryptor($shop->merchant_name) : $this->encryptor($shop->contact_name),//开户名称
                'account_bank'                  =>   $shop->account_bank,//开户银行
                'bank_address_code'             =>   $shop->bank_address_code,//开户银行省市编码
                'bank_branch_id'                =>   $shop->bank_branch_id,//开户银行联行号
                'bank_name'                     =>   $shop->bank_name,//开户银行全称（含支行）
                'account_number'                =>   $this->encryptor($shop->account_number),//银行账号
            ],

        ];
        if($shop->subject_type != "SUBJECT_TYPE_INDIVIDUAL" && $shop->subject_type != "SUBJECT_TYPE_ENTERPRISE"){
            $arr['subject_info']['certificate_info'] =   [//主体为政府机关/事业单位/其他组织
                'cert_copy'                 => $shop->cert_copy? $this->wx_upload_image($shop->cert_copy):'',//登记证书照片
                'cert_type'                 => $shop->cert_type??"",//登记证书类型
                'cert_number'               => $shop->cert_number??"",//证书号
                'merchant_name'             => $shop->merchant_name??"",//商户名称
                'company_address'           => $shop->company_address??"",//注册地址
                'legal_person'              => $shop->contact_name??"",//法定代表人
                'period_begin'              => $shop->certificate_period_begin??"",//有效期限开始日期
                'period_end'                => $shop->certificate_period_end??"",//有效期限结束日期
            ];
        }
        $res = $this->ApplyShop($arr);

        if($res['applyment_id']){
            if($type){
                \app\api\model\wanlshop\Shop::where('id',$shop_id)->update([
                    'applyment_id'=>$res['applyment_id'],
                    'business_code'=>$business_code
                ]);
            }else{
                AddressSpot::where('id',$shop_id)->update([
                    'applyment_id'=>$res['applyment_id'],
                    'business_code'=>$business_code
                ]);
            }

        }
    }
    public function ceshi()
    {
//        $arr = [
//            'business_code'             => "",//业务申请编号
//            "contact_info"              => [//超级管理员信息
//                'contact_type'              => "",//超级管理员类型
//                'contact_name'              => "",//超级管理员姓名
//                'contact_id_doc_type'       => "",//超级管理员证件类型
//                'contact_id_number'         => "",//超级管理员身份证件号码
//                'contact_id_doc_copy'       => "",//超级管理员证件正面照片
//                'contact_id_doc_copy_back'  => "",//超级管理员证件反面照片
//                'contact_period_begin'      => "",//超级管理员证件有效期开始时间
//                'contact_period_end'        => "",//超级管理员证件有效期结束时间
//                'openid'                    => "",//超级管理员微信OpenID
//                'mobile_phone'              => "",//联系手机
//                'contact_email'             => "",//联系邮箱
//            ],
//            'subject_info'              =>  [//主体资料
//                'subject_type'              => "",//主体类型
//                'business_license_info'     => [//-营业执照  主体为个体户/企业
//                    'license_copy'              => "",//营业执照照片
//                    'license_number'            => "",//注册号/统一社会信用代码
//                    'merchant_name'             => "",//注册号/商户名称
//                    'legal_person'              => "",//个体户经营者/法人姓名
//                    'license_address'           => "",//个体户经营者/注册地址
//                    'period_begin'              => "",//有效期限开始日期
//                    'period_end'                => "",//有效期限结束日期
//                ],
//                'certificate_info'      =>  [//主体为政府机关/事业单位/其他组织
//                    'cert_copy'                 => "",//登记证书照片
//                    'cert_type'                 => "",//登记证书类型
//                    'cert_number'               => "",//证书号
//                    'merchant_name'             => "",//商户名称
//                    'company_address'           => "",//注册地址
//                    'legal_person'              => "",//法定代表人
//                    'period_begin'              => "",//有效期限开始日期
//                    'period_end'                => "",//有效期限结束日期
//                ],
//                'identity_info'         =>  [//经营者/法人身份证件
//                    'id_holder_type'            => "",//证件持有人类型
//                    'id_doc_type'               => "",//证件类型
//                    "id_card_info"              => [
//                        'id_card_copy'              =>  "",//身份证人像面照片
//                        'id_card_national'          =>  "",//身份证国徽面照片
//                        'id_card_name'              =>  "",//身份证姓名
//                        'id_card_number'            =>  "",//身份证号码
//                        'id_card_address'           =>  "",//身份证居住地址
//                        'card_period_begin'         =>  "",//身份证有效期开始时间
//                        'card_period_end'           =>  "",//身份证有效期结束时间
//                    ]
//                ],
//
//            ],
//            "business_info"             =>  [//-经营资料
//                'merchant_shortname'            => "",//商户简称
//                ''                              => "",//客服电话
//                'sales_info'                => [//经营场景
//                    'sales_scenes_type'             =>  [],//经营场景类型
//                    'mp_info'               => [//公众号场景
//                        'mp_appid'                  =>  ""//服务商公众号AppID
//                    ],
//                    'mini_program_info'     => [//小程序场景
//                        'mini_program_appid'        =>  "",//服务商小程序AppID
//                    ],
//                ],
//            ],
//
//            "settlement_info"           =>  [//-结算规则
//                'settlement_id'                 =>  "",//入驻结算规则ID
//                'qualification_type'            =>  "",//所属行业
//            ],
//
//            "bank_account_info"         =>  [//--结算银行账户
//                'bank_account_type'             =>  "",//账户类型
//                'account_name'                  =>  "",//开户名称
//                'account_bank'                  =>  "",//开户银行
//                'bank_address_code'             =>  "",//开户银行省市编码
//                'bank_branch_id'                =>  "",//开户银行联行号
//                'bank_name'                     =>  "",//开户银行全称（含支行）
//                'account_number'                =>  "",//银行账号
//            ],
//
//        ];

//        $this->ApplyShop($arr);
    }

    //子商户号入驻
    public function ApplyShop($arr)
    {
        try {
            $resp = $this->instance
                ->chain('v3/applyment4sub/applyment/')
                ->post([
                    'json' => $arr,
                    'headers' => [
                        // $platformCertificateSerial 见初始化章节
                        'Wechatpay-Serial' => $this->platformCertificateSerial,
                    ],
                ]);

        } catch (\GuzzleHttp\Exception\ClientException $e) {
            $response = $e->getResponse();
            $statusCode = $response->getStatusCode();

            if ($statusCode == 400) {
                $errorBody = json_decode($response->getBody()->getContents(), true);
                $errorMessage = $errorBody['message'] ?? '请求错误：请确认提交的数据格式和内容是否正确。';
                $this->error(__($errorMessage));
            } else {
                $this->error(__('请确认提交的数据格式和内容是否正确'));
            }
        } catch (ValidateException $e) {
            $this->error(__($e->getMessage()));
        } catch (\Exception $e) {
            $this->error(__('请确认提交的数据格式和内容是否正确'));
        }
        if($resp->getStatusCode() == 200){
            $result = json_decode($resp->getBody()->getContents(),true);
            return $result;
        }else{
            return " ";
        }
    }

    //查询子商户入驻状态
    public function QueryApply($applyment_id)
    {
        try {
            $resp = $this->instance
                ->chain('v3/applyment4sub/applyment/applyment_id/'.$applyment_id.'/')
                ->get();
        } catch (\GuzzleHttp\Exception\ClientException $e) {
        $response = $e->getResponse();
        $statusCode = $response->getStatusCode();

        if ($statusCode == 400) {
        $errorBody = json_decode($response->getBody()->getContents(), true);
        $errorMessage = $errorBody['message'] ?? '请求错误：请确认提交的数据或者重新提交申请。';
        $this->error(__($errorMessage));
        } else {
            $this->error(__('请确认提交的数据或者重新提交申请'));
        }
        } catch (ValidateException $e) {
            $this->error(__($e->getMessage()));
        } catch (\Exception $e) {
            $this->error(__('请确认提交的数据或者重新提交申请'));
        }
        if($resp->getStatusCode() == 200){
            $result = json_decode($resp->getBody()->getContents(),true);
            return $result;
        }else{
            return " ";
        }
    }

    //微信文字加密方法
    public function encryptor($msg)
    {
        $platformPublicKeyInstance = Rsa::from($this->platformCertificateFilePath, Rsa::KEY_TYPE_PUBLIC);
        return Rsa::encrypt($msg, $platformPublicKeyInstance);
    }


    //微信上传图片
    public function wx_upload_image($image)
    {
        $media = new MediaUtil(ROOT_PATH.'public'.$image);

        $resp = $this->instance->chain('v3/merchant/media/upload')->post([
            'body' => $media->getStream(),
            'headers' => [
                'content-type' => $media->getContentType(),
            ]
        ]);
        if($resp->getStatusCode() == 200){
            $result = json_decode($resp->getBody()->getContents(),true);
            return $result['media_id'];
        }else{
            return " ";
        }
    }
    public function curlRequest($config, $request, $json = true)
    {
        $url = $config['url'];          // 请求路径
        $method = $config['method'];    // 请求方法
        $headers = $config['headers'];  // 请求头部

        // 如果请求数据是以form-data格式发送，json应为false
        $body = $json ? json_encode($request) : $request;
        // 如果使用multipart/form-data，不需要将body转换成json
        // 这里只需要将请求数据保留为数组形式
        if (!$json && is_array($body)) {
            $body = $request; // 保持原来的数组形式
        }
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_HEADER, 0);//返回response头部信息
        curl_setopt($curl, CURLOPT_FAILONERROR, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_POST, true); // 发送一个常规的Post请求
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        // 如果使用multipart/form-data，传递数组形式的请求数据
        if (!$json) {
            curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
        } else {
            curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
        }
        $result = curl_exec($curl);
        $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        curl_close($curl);
        return [
            'body' => $result,
            'httpCode' => $httpCode
        ];
    }
    //h5下单
    public function h5()
    {
//        $http = new Http();
//        $url = ' https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx1883952ab26b1519&secret=318318&code=061Ki1100UFMyS1Rwf000ZRNuz3Ki11N&grant_type=authoriztion_code';
//        $response = $http->parseJSON($http->get($url, []));
//        halt($response);
        $arr = [
            'sp_appid'=>'wx1883952ab26b1519',
            'sp_mchid'=>'1680098009',
            'sub_mchid'=>'1682334309',
            'description'=>'测试商品描述',
            'out_trade_no'=>'wx'.time(),
            'notify_url'=>'https://c.hrbyuecai.com/api/wanlshop/separate/notify_url',
            'amount'=>[
                'total'=>10,
                'currency'=> 'CNY'
            ],
            'settle_info'=>[
                'profit_sharing'=>true
            ],
            'payer'=>[
                'sp_openid'=>'oeIb46dAqrDiKFK2WK6PBzNtuIrw',
            ]
        ];
//        $resp = $this->curlRequest([
//            'url'=>'https://api.mch.weixin.qq.com/v3/pay/partner/transactions/jsapi',
//            'method'=>'POST',
//            'headers'=>[
//                'Content-Type: application/json',
//                'Accept: application/json',
//                'User-Agent: application/json',
//            ]
//        ],$arr);
        $resp = $this->instance
            ->chain('/v3/pay/partner/transactions/jsapi')
            ->post([
                'json' => $arr,
                'headers' => [

                    'Content-Type: application/json',
                    'Accept: application/json',
                    'User-Agent: application/json',
                ],
            ]);
        if($resp->getStatusCode() == 200){
            $appid = 'wx1883952ab26b1519';
            $result = json_decode($resp->getBody()->getContents(),true);
            $noncestr = substr(str_replace(['+', '/', '='], '', base64_encode(random_bytes(16))), 0, 16);
            $timestamp = (string)time();
            $package = 'prepay_id='.$result['prepay_id'];
            // 待签名数据
            $signData = [
                $appid,
                $timestamp,
                $noncestr,
                $package,
                ''
            ];

            // 创建待签名字符串，每一行以\n结束
            $signDataString = implode("\n", $signData);
            $signature = Rsa::sign($signDataString . "\n", $this->merchantPrivateKeyInstance);
            $base64Signature = base64_encode($signature);
            $data = [
                'appid'=>  'wx1883952ab26b1519',
                'partnerid'=>'1680098009',
                'prepayid'=>$result['prepay_id'],
                'package'=>$package,
                'noncestr'=>$noncestr,
                'timestamp'=>$timestamp,
                "sign"=>$base64Signature,
            ];
            $this->success('ok',$data);
        }else{
            return " ";
        }
    }
    public function notify_url()
    {
        $param = $this->request->param();
        TestContent::create([
            'content'=>json_encode($param)
        ]);
    }
    public function gerOpenId()
    {
        $param = $this->request->param('code');
        $resp = $this->curlRequest([
            'url'=>'https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx1883952ab26b1519&secret=397d42b98fd9bc07df5eb2a6296f7bca&code='.$param.'&grant_type=authorization_code',
            'method'=>'GET',
            'headers'=>[
                'Content-Type: application/json',
            ]
        ],  []);
    }
    public function refund()
    {

    }
}